package com.shop.web.admin_menu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.web.admin_menu.entity.AssignParm;
import com.shop.web.admin_menu.entity.AdminMenu;
import com.shop.web.admin_menu.mapper.AdminMenuMapper;
import com.shop.web.admin_menu.service.AdminMenuService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class AdminMenuServiceImpl extends ServiceImpl<AdminMenuMapper, AdminMenu> implements AdminMenuService {

    @Override
    @Transactional
    public void saveMenu(AssignParm parm) {
        //先删除，再插入
        //1、删除
        QueryWrapper<AdminMenu> query = new QueryWrapper<>();
        query.lambda().eq(AdminMenu::getUserId,parm.getAssId());
        this.baseMapper.delete(query);
        //2、删除成功，再插入
        this.baseMapper.saveMenu(parm.getAssId(),parm.getList());
    }
}
